<?php 
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Member\Controller;
use \Member\Controller\InitController;
if (!defined('MODULE_CACHE')) define('MODULE_CACHE', DATA_PATH.'caches_model/');
class ConvertController extends InitController {
	public function _initialize() {
		parent::_initialize();
		$this->db = D('Member');
		$this->detail_db = D('Member_detail');
		$this->convert_db = D('Convert');
	}

	/**
	 * 处理兑换记录
	 */
	public function index(){

		$data['number'] = I('credit_num');
		$data['name'] = I('name');

		$data['userid'] = $_COOKIE['khy_userid'];
		$data['consignee'] = I('nickname');
		$data['time'] = time();
		$data['shop_type'] = I('shop_type');
		$data['credit_type'] = I('credit_type');
		$result = $this->convert_db->add($data);
		if($result){	
			$data['credit_type'] == 'bean' ? $credit_type = 'u_bean' : $credit_type = 'u_coin';
			$data['name'] = '兑换商品：'.$data['name'];
			score_change($data['userid'],$data['name'],$data['number'],$credit_type,0);
			echo 1;
		}else{
			echo 2;
		}

	}
	/*兑换记录*/
	public function prize(){
		$SEO=seo(0,"我的奖品信息");
		$pagecurr = max(1,I('page',0,'intval'));
		$pagesize = 10;
		$userid = $_COOKIE['khy_userid'];
		$count = $this->convert_db->where(array('userid'=>$userid))->count();

		$tmps = $this->convert_db->where(array('userid'=>$userid))->page($pagecurr,$pagesize)->order('time DESC')->select();
		$pages = page($count,$pagesize);
		include template('convert');

	}
	 
}